/**
 * 本模块主要存储了生成测点清单的相关方法
 */
import systemdemo from '@/components/ts/systemdemo'
import {computed} from 'vue'
import {storeToRefs} from 'pinia'
import {useCCPPStore} from '@/store'
import lodash from 'lodash'

const store = useCCPPStore()

const {
    selectedUnitType,
    correct_paras,
    selectedGasFlowType,
    calIndex
} = storeToRefs(store)

const correct_para_names = computed(() => {
    return correct_paras.value.map(item => item instanceof String ? item : (item as any).name)
})

const spec1 = computed(() => {
    let res
    if (selectedUnitType.value == '二拖一') {
        res = [
            ['', '燃机1发电功率', 'MW'],
            ['', '燃机2发电功率', 'MW'],
            ['', '汽机发电功率', 'MW'],
            ['', '燃机1励磁功率', 'MW'],
            ['', '燃机2励磁功率', 'MW'],
            ['', '汽机励磁功率', 'MW']

        ]
    } else if (selectedUnitType.value == '一拖一单轴') {
        res = [
            ['', '发电功率', 'MW'],
            ['', '发电机励磁功率', 'MW']

        ]
    } else {
        res = [
            ['', '燃机发电功率', 'MW'],
            ['', '汽机发电功率', 'MW'],
            ['', '燃机发电机励磁功率', 'MW'],
            ['', '汽机发电机励磁功率', 'MW']
        ]
    }

    return res
})
const spec2 = computed(() => {
    let res
    if (selectedUnitType.value == '二拖一') {
        res = [
            ['', '燃机发电机1功率因数', '/'],
            ['', '燃机发电机2功率因数', '/'],
            ['', '汽机发电机功率因数', '/'],
            ['', '燃机发电机1频率', 'Hz'],
            ['', '燃机发电机2频率', 'Hz'],
            ['', '汽机发电机频率', 'Hz'],
            ...(
                lodash.includes(correct_para_names.value, '燃机发电机氢压') ? [
                    ['', '燃机发电机1氢压', 'MPa'],
                    ['', '燃机发电机2氢压', 'MPa']
                ] : []
            ),
            ...(
                lodash.includes(correct_para_names.value, '汽机发电机氢压') ? [
                    ['', '汽机发电机氢压', 'MPa']
                ] : []
            )
        ]
    } else if (selectedUnitType.value == '一拖一单轴') {
        res = [
            ['', '发电机功率因数', '/'],
            ...(lodash.includes(correct_para_names.value, '发电机转速') ? [
                    ['', '发电机转速', 'rpm']
                ] : []
            ),
            ...(lodash.includes(correct_para_names.value, '发电机氢压') ? [
                    ['', '发电机氢压', 'MPa']
                ] : []
            )
        ]
    } else {
        res = [
            ['', '燃机发电机功率因数', '/'],
            ['', '汽机发电机功率因数', '/'],
            ['', '燃机发电机频率', 'Hz'],
            ['', '汽机发电机频率', 'Hz'],
            ...(
                lodash.includes(correct_para_names.value, '燃机发电机氢压') ? [
                    ['', '燃机发电机氢压', 'MPa']
                ] : []
            ),
            ...(
                lodash.includes(correct_para_names.value, '汽机发电机氢压') ? [
                    ['', '汽机发电机氢压', 'MPa']
                ] : []
            )
        ]
    }

    res = [...res, ...( // 如果有循环水温度对功率修正时，添加循环水温度测点
        lodash.includes(correct_para_names.value, '循环水温度对功率') ? [
            ['', '凝汽器进口循环水温度', '℃']
        ] : []
    ), // 如果有循环水流量对功率修正时，添加循环水流量测点
        ...(lodash.includes(correct_para_names.value, '循环水流量对功率') ? [
            ['可选填（忽略）', '凝汽器进口循环水流量', 't/h']
        ] : [])
    ]
    return res
})
// 生成测点清单按钮点击事件
export const handleGeneratePoints = () => {
    store.printToTerm(`开始生成${selectedUnitType.value}机组测点清单...`)
    let title = [['', '测点名称', '单位']]
    let flowItem
    if (selectedGasFlowType.value === '涡轮流量计_体积流量') {
        flowItem = [['', '天然气体积流量', 'Nm3/h']]
    } else if (selectedGasFlowType.value === '涡轮流量计_脉冲计数') {
        flowItem = [['', '涡轮流量计脉冲数', 'Pulses/h'], ['可选填', '天然气体积流量', 'Nm3/h']]
    } else {
        flowItem = [['', '天然气质量流量', 'kg/h']]
    }
    let commonList = [
        ['', '大气压力', 'kPa'],
        ['', '大气温度', '℃'],
        ['', '环境相对湿度', '%'],
        ['', 'FGH入口天然气压力', 'MPa'],
        ['', 'FGH入口天然气温度', '℃'],
        ...flowItem,
        ['', '凝汽器背压', 'kPa'],
        ['', '', ''],
        ['天然气组分体积分数', '', ''],
        ['甲烷', 'CH4', '%'],
        ['氮气', 'N2', '%'],
        ['二氧化碳', 'CO2', '%'],
        ['乙烷', 'C2H6', '%'],
        ['丙烷', 'C3H8', '%'],
        ['水', 'H2O', '%'],
        ['硫化氢', 'H2S', '%'],
        ['氢气', 'H2', '%'],
        ['一氧化碳', 'CO', '%'],
        ['氧气', 'O2', '%'],
        ['异丁烷', 'i-C4H10', '%'],
        ['正丁烷', 'n-C4H10', '%'],
        ['异戊烷', 'i-C5H12', '%'],
        ['正戊烷', 'n-C5H12', '%'],
        ['己烷', 'C6H14', '%'],
        ['庚烷', 'C7H14', '%'],
        ['辛烷', 'C8H14', '%'],
        ['壬烷', 'C9H14', '%'],
        ['癸烷', 'C10H14', '%'],
        ['氦气', 'He', '%'],
        ['氩气', 'Ar', '%']
    ]

    // 将spec和commonList进行拼接
    let data = [...title, ...spec1.value, ...spec2.value, ...commonList]

    if (lodash.includes(calIndex.value, '汽机')) {
        data = [
            ...data,
            ...[
                ['', '', ''],
                ['', '余热锅炉高压给水压力', 'MPa'],
                ['', '高压主蒸汽压力', 'MPa'],
                ['', '高压缸排汽压力', 'MPa'],
                ['', '余热锅炉高压给水温度', '℃'],
                ['', '高压主蒸汽温度', '℃'],
                ['', '高压缸排汽温度', '℃'],
                ['', '余热锅炉高压给水流量', 't/h'],
                ['', '', ''],

            ]
        ]
    }

    systemdemo.clear_sheet('测点清单')
    systemdemo.create_new_sheet('测点清单')
    systemdemo.set_cells(1, 1, data)
    systemdemo.auto_fit_columns()
}